#
#
CLEANFILES = *~
DISTCLEANFILES = *~

if ECM_TESTING
SUBDIRS_test = test
endif

SUBDIRS = lib src $(SUBDIRS_test) ctl

DIST_SUBDIRS = buildtool lib src test ctl

ECM_NAME ?= $(PACKAGE)
ECM_PACKAGE_TARBALL = rpm/$(ECM_NAME)-$(VERSION).tar.gz
ECM_TARBALL = $(PACKAGE)-$(VERSION).tar.gz
CLX_HOME ?= /usr/clx

RPMROOT ?= ~/rpmbuild

.PHONY: rpm

rpm: $(ECM_PACKAGE_TARBALL)
	cp $(ECM_PACKAGE_TARBALL) $(RPMROOT)/SOURCES/;	\
	cp rpm/ecm.spec.tmpl $(RPMROOT)/SPECS/$(ECM_NAME).spec;	\
	CLX_HOME=$(CLX_HOME) ECM_NAME=$(ECM_NAME) VERSION=$(VERSION) rpmbuild -bb $(RPMROOT)/SPECS/$(ECM_NAME).spec

$(ECM_PACKAGE_TARBALL): $(ECM_TARBALL)
	@if [ $(PACKAGE) = $(ECM_NAME) ]; then			\
		cp -f $(ECM_TARBALL) $(ECM_PACKAGE_TARBALL);	\
	else							\
		rm -rf .tarball_temp;				\
		mkdir .tarball_temp;				\
		cd .tarball_temp;				\
		tar xzf ../$(ECM_TARBALL);			\
		mv $(PACKAGE)-$(VERSION) $(ECM_NAME)-$(VERSION);	\
		tar czf ../$(ECM_PACKAGE_TARBALL) $(ECM_NAME)-$(VERSION); \
		cd ..;						\
		rm -rf .tarball_temp;				\
	fi

EXTRA_DIST = rpm/ecm.spec.tmpl
